package com.h3c.nem.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.h3c.nem.dto.PsaTbTrainWorkerDTO;
import com.h3c.nem.dto.TbTeacherDTO;
import com.h3c.nem.service.ITbTrainWorkerService;
import com.h3c.nem.dto.TbTrainWorkerDTO;
import com.h3c.nem.utils.ReturnCodeData;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSON;

import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.List;

/**
 * TbTrainWorker 接口
 *
 * @Author: j26296
 * @Date: 2022-06-20
 * Description: tb_train_worker controller
 * Version: 1.0
 * Copyright (C), 2022-2022, h3c
 */
@RestController
@CrossOrigin
@Slf4j
@RequestMapping(value = "/tbTrainWorker",produces = "application/json;charset=utf-8")
public class TbTrainWorkerController {

    @Resource
    private ITbTrainWorkerService tbTrainWorkerService;
/*

    */
/**
     * @title: queryFuzzyListForPage
     * @description: 列表分页模糊查询
     * @params: [ paramsDTO, currentPage, pageSize ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-06-20
     * @version: 1.0
     * @author: j26296
     *//*

    @RequestMapping(value = "/queryFuzzyListForPage", method = RequestMethod.GET)
    public ResponseObject queryFuzzyListForPage(@ModelAttribute TbTrainWorkerDTO paramsDTO,
                                                            @RequestParam(name = "currentPage", required = true) Integer currentPage,
                                                            @RequestParam(name = "pageSize", required = true) Integer pageSize) {
        log.info("准备执行  列表分页模糊查询，传入的参数为：" + JSON.toJSONString(paramsDTO));
        //分页
        Page page = PageHelper.startPage(currentPage, pageSize);
        //执行
        List<TbTrainWorkerDTO> resultDTOList = tbTrainWorkerService.selectFuzzyByDto(paramsDTO);
        PageInfo<TbTrainWorkerDTO> pageInfo = page.toPageInfo();
        pageInfo.setList(resultDTOList);
        log.info("执行列表分页模糊查询完成，准备返回的结果为：" + JSON.toJSONString(pageInfo));
        return ResponseObject.success("列表分页模糊查询成功", pageInfo);
    }

    */
/**
     * @title: queryListForPage
     * @description: 列表分页精确查询
     * @params: [ paramsDTO, currentPage, pageSize ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-06-20
     * @version: 1.0
     * @author: j26296
     *//*

    @RequestMapping(value = "/queryListForPage", method = RequestMethod.GET)
    public ResponseObject queryListForPage(@ModelAttribute TbTrainWorkerDTO paramsDTO,
                                                       @RequestParam(name = "currentPage", required = true) Integer currentPage,
                                                       @RequestParam(name = "pageSize", required = true) Integer pageSize) {
        log.info("准备执行  列表分页查询，传入的参数为：" + JSON.toJSONString(paramsDTO));
        //分页
        Page page = PageHelper.startPage(currentPage, pageSize);
        //执行
        List<TbTrainWorkerDTO> resultDTOList = tbTrainWorkerService.selectFuzzyByDto(paramsDTO);
        PageInfo<TbTrainWorkerDTO> pageInfo = page.toPageInfo();
        pageInfo.setList(resultDTOList);
        log.info("执行列表分页查询完成，准备返回的结果为：" + JSON.toJSONString(pageInfo));
        return ResponseObject.success("列表分页查询成功", pageInfo);
    }


    */
/**
     * @title: save
     * @description: 数据插入
     * @params: [ paramsDTO ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-06-20
     * @version: 1.0
     * @author: j26296
     *//*

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResponseObject save(@RequestBody TbTrainWorkerDTO paramsDTO) {
        log.info("准备执行 数据插入，传入的参数为：" + JSON.toJSONString(paramsDTO));
        //执行
        Integer result = tbTrainWorkerService.insertDto(paramsDTO);
        log.info("执行 数据插入完成，准备返回的结果为：" + JSON.toJSONString(result));
        return ResponseObject.success("数据插入成功", result);
    }

    */
/**
     * @title: update
     * @description: 数据修改
     * @params: [ paramsDTO ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-06-20
     * @version: 1.0
     * @author: j26296
     *//*

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseObject update(@RequestBody TbTrainWorkerDTO paramsDTO) {
        log.info("准备执行 数据修改，传入的参数为：" + JSON.toJSONString(paramsDTO));
        //执行
        Integer result = tbTrainWorkerService.updateDto(paramsDTO);
        log.info("执行 数据修改完成，准备返回的结果为：" + JSON.toJSONString(result));
        return ResponseObject.success("数据修改成功", result);
    }

    */
/**
     * @title: delete
     * @description: 数据删除
     * @params: [ id ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-06-20
     * @version: 1.0
     * @author: j26296
     *//*

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ResponseObject delete(@RequestBody TbTrainWorkerDTO paramsDTO) {
        log.info("准备执行 数据删除，传入的参数为：" + JSON.toJSONString(paramsDTO));
        //执行
        Integer result = tbTrainWorkerService.deleteDto(paramsDTO);
        log.info("执行 数据删除 完成，准备返回的结果为：" + JSON.toJSONString(result));
        return ResponseObject.success("数据删除", result);
    }
*/
    /**
     * @title: queryFuzzyListForPage
     * @description: 列表分页模糊查询
     * @params: [ paramsDTO, currentPage, pageSize ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    @ApiOperation(value = "信息查询", notes = "信息查询")
    @RequestMapping(value = "/queryFuzzyForPage", method = RequestMethod.GET)
    public ResponseEntity<JSONObject> queryFuzzyForPage(@ModelAttribute TbTrainWorkerDTO paramsDTO)
                                                        {
        log.info("准备执行  列表分页模糊查询，传入的参数为：" + JSON.toJSONString(paramsDTO));
        JSONObject data = new JSONObject();
        try {
            TbTrainWorkerDTO dto = tbTrainWorkerService.selectFuzzyByDto(paramsDTO);
            data.put("data",dto);
            data.put("msg", "列表分页模糊查询成功");
            data.put("code", ReturnCodeData.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("执行列表分页模糊查询异常，异常信息为：" + JSON.toJSONString(e));
            data.put("msg", e.toString());
            data.put("code", ReturnCodeData.FAIL);
        }
        log.info("执行列表分页模糊查询完成，准备返回的结果为：" + JSON.toJSONString(data));
        return new ResponseEntity<>(data, HttpStatus.ACCEPTED);
    }

    /**
     * @title: update
     * @description: 数据修改
     * @params: [ paramsDTO ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    @ApiOperation(value = "数据修改", notes = "数据修改")
    @ApiImplicitParams({@ApiImplicitParam(name = "paramsDTO", value = "实体参数信息", required = true, dataType = "TbTeacher", paramType = "body")})
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseEntity<JSONObject> update(@RequestBody TbTrainWorkerDTO paramsDTO) {
        log.info("准备执行 数据修改，传入的参数为：" + JSON.toJSONString(paramsDTO));
        JSONObject data = new JSONObject();
        try {
            //执行
            Integer result = tbTrainWorkerService.updateDto(paramsDTO);
            data.put("data",result);
            data.put("msg", "数据修改成功");
            data.put("code", ReturnCodeData.SUCCESS);
        } catch (Exception e) {
            log.error("执行 数据修改 异常，异常信息为：" + JSON.toJSONString(e));
            data.put("msg", e.toString());
            data.put("code", ReturnCodeData.FAIL);
        }
        log.info("执行 数据修改完成，准备返回的结果为：" + JSON.toJSONString(data));
        return new ResponseEntity<>(data, HttpStatus.ACCEPTED);
    }
    /**
     * @title: update
     * @description: 数据修改
     * @params: [ paramsDTO ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    @ApiOperation(value = "数据提交", notes = "数据提交")
    @ApiImplicitParams({@ApiImplicitParam(name = "paramsDTO", value = "实体参数信息", required = true, dataType = "TbTeacher", paramType = "body")})
    @RequestMapping(value = "/submit", method = RequestMethod.POST)
    public ResponseEntity<JSONObject> submit(@RequestBody TbTrainWorkerDTO paramsDTO) {
        log.info("准备执行 数据修改，传入的参数为：" + JSON.toJSONString(paramsDTO));
        JSONObject data = new JSONObject();
        try {
            //执行
            tbTrainWorkerService.submitOneMail(paramsDTO);
            data.put("data","");
            data.put("msg", "数据提交成功");
            data.put("code", ReturnCodeData.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("执行 数据修改 异常，异常信息为：" + JSON.toJSONString(e));
            data.put("msg", e.toString());
            data.put("code", ReturnCodeData.FAIL);
        }
        log.info("执行 数据修改完成，准备返回的结果为：" + JSON.toJSONString(data));
        return new ResponseEntity<>(data, HttpStatus.ACCEPTED);
    }


    @RequestMapping(value = "/reback", method = RequestMethod.POST)
    public ResponseEntity<JSONObject> reback(@RequestBody PsaTbTrainWorkerDTO paramsDTO) {
        log.info("准备执行 数据修改，传入的参数为：" + JSON.toJSONString(paramsDTO));
        JSONObject data = new JSONObject();
        try {
            //执行
            tbTrainWorkerService.reback(paramsDTO);
            data.put("data","");
            data.put("msg", "数据提交成功");
            data.put("code", ReturnCodeData.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("执行 数据修改 异常，异常信息为：" + JSON.toJSONString(e));
            data.put("msg", e.toString());
            data.put("code", ReturnCodeData.FAIL);
        }
        log.info("执行 数据修改完成，准备返回的结果为：" + JSON.toJSONString(data));
        return new ResponseEntity<>(data, HttpStatus.ACCEPTED);
    }

    @ApiOperation(value = "信息查询", notes = "信息查询")
    @RequestMapping(value = "/queryLetterContent", method = RequestMethod.GET)
    public ResponseEntity<JSONObject> queryLetterContent(@ModelAttribute TbTrainWorkerDTO paramsDTO)
    {
        log.info("准备执行  列表分页模糊查询，传入的参数为：" + JSON.toJSONString(paramsDTO));
        JSONObject data = new JSONObject();
        try {
            TbTrainWorkerDTO dto = tbTrainWorkerService.getLetterContent(paramsDTO);
            data.put("data",dto);
            data.put("msg", "列表分页模糊查询成功");
            data.put("code", ReturnCodeData.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("执行列表分页模糊查询异常，异常信息为：" + JSON.toJSONString(e));
            data.put("msg", e.toString());
            data.put("code", ReturnCodeData.FAIL);
        }
        log.info("执行列表分页模糊查询完成，准备返回的结果为：" + JSON.toJSONString(data));
        return new ResponseEntity<>(data, HttpStatus.ACCEPTED);
    }

    @RequestMapping(value = "/searchLetterContent", method = RequestMethod.GET)
    public ResponseEntity<JSONObject> searchLetterContent(@RequestBody PsaTbTrainWorkerDTO paramsDTO) {
        log.info("准备执行 数据修改，传入的参数为：" + JSON.toJSONString(paramsDTO));
        JSONObject data = new JSONObject();
        try {
            //执行
            PsaTbTrainWorkerDTO psaTbTrainWorkerDTO =  tbTrainWorkerService.searchLetterContent(paramsDTO);
            data.put("data",psaTbTrainWorkerDTO);
            data.put("msg", "查询成功");
            data.put("code", ReturnCodeData.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("执行 数据查询 异常，异常信息为：" + JSON.toJSONString(e));
            data.put("msg", e.toString());
            data.put("code", ReturnCodeData.FAIL);
        }
        log.info("执行 查询 成功，准备返回的结果为：" + JSON.toJSONString(data));
        return new ResponseEntity<>(data, HttpStatus.ACCEPTED);
    }

}
